//package com.example.lcqexcel.test;
//
//import com.alibaba.excel.enums.CellDataTypeEnum;
//import com.alibaba.excel.metadata.CellData;
//import com.alibaba.excel.metadata.Head;
//import com.alibaba.excel.util.CollectionUtils;
//import com.alibaba.excel.write.handler.AbstractCellWriteHandler;
//import com.alibaba.excel.write.handler.CellWriteHandler;
//import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
//import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
//import com.example.lcqexcel.demo.CellImgMultiData;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.util.Units;
//
//import java.util.List;
//
///**
// * @ClassName CellImgMultiCellWriteHandler
// * @Description
// * @Author lichuanqi
// * @Date 2021/9/29 13:52
// * @Version 1.0
// **/
//public class CellImgMultiCellWriteHandler extends AbstractCellWriteHandler {
//    @Override
//    public void beforeCellCreate(WriteSheetHolder writeSheetHolder,
//                                 WriteTableHolder writeTableHolder,
//                                 Row row, Head head,
//                                 Integer columnIndex,
//                                 Integer relativeRowIndex,
//                                 Boolean isHead) {
//
//        //writeSheetHolder.getSheet().setColumnWidth(columnIndex, 23*2);
//
//    }
//
//    @Override
//    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//        super.afterCellCreate(writeSheetHolder, writeTableHolder, cell, head, relativeRowIndex, isHead);
//    }
//
//    @Override
//    public void afterCellDataConverted(WriteSheetHolder writeSheetHolder,
//                                       WriteTableHolder writeTableHolder,
//                                       CellData cellData,
//                                       Cell cell,
//                                       Head head,
//                                       Integer relativeRowIndex,
//                                       Boolean isHead) {
//        if (isHead){
//            return;
//        }
//
//        if (cellData.getData()!=null && cellData.getData() instanceof CellImgMultiData){
//            cellData.setType(CellDataTypeEnum.EMPTY);
//        }
//    }
//
//    @Override
//    public void afterCellDispose(WriteSheetHolder writeSheetHolder,
//                                 WriteTableHolder writeTableHolder,
//                                 List<CellData> cellDataList,
//                                 Cell cell,
//                                 Head head,
//                                 Integer relativeRowIndex,
//                                 Boolean isHead) {
//        if (isHead ||
//            CollectionUtils.isEmpty(cellDataList) ||
//            !(cellDataList.get(0).getData() instanceof CellImgMultiData)){
//            return;
//        }
//        CellImgMultiData cellImgMultiData = (CellImgMultiData)cellDataList.get(0).getData();
//        List<byte[]> imageDataList = cellImgMultiData.getImageDataList();
//        if (CollectionUtils.isEmpty(imageDataList)){
//            return;
//        }
//
//       // writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 23 * 256 * imageDataList.size());
//        //writeSheetHolder.getSheet().getRow(cell.getRowIndex()).setHeight();
//        writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 23*256*imageDataList.size());
//        for (int i = 0;i < imageDataList.size(); i++){
//            byte[] imageByte = imageDataList.get(i);
//            drawImg(writeSheetHolder, cell, i, imageByte);
//        }
//
//
//    }
//
//    private void drawImg(WriteSheetHolder writeSheetHolder, Cell cell, int i, byte[] imageByte) {
//        Sheet sheet = writeSheetHolder.getSheet();
//        Workbook workbook = sheet.getWorkbook();
//        Drawing drawing = sheet.getDrawingPatriarch();
//        CreationHelper helper = workbook.getCreationHelper();
//        if (drawing==null){
//            drawing = sheet.createDrawingPatriarch();
//        }
//
//        int index = workbook.addPicture(imageByte, HSSFWorkbook.PICTURE_TYPE_PNG);
//        ClientAnchor anchor = helper.createClientAnchor();
//
//        int picWidth = 23*256;
//        anchor.setDx1(picWidth*i);
//        anchor.setDx2(picWidth+picWidth*i);
//        anchor.setDy1(0);
//        anchor.setDy2(0);
//
//        anchor.setRow1(cell.getRowIndex());
//        anchor.setRow2(cell.getRowIndex()+1);
//        anchor.setCol1(cell.getColumnIndex());
//        anchor.setCol2(cell.getColumnIndex()+1);
//
//
//        anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
//        drawing.createPicture(anchor, index);
//    }
//}
